package com.leyou.item.dto;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.leyou.common.dto.BaseDTO;
import com.leyou.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@TableName("tb_user")
@Data
@NoArgsConstructor //无参的构造方法
@EqualsAndHashCode(callSuper = true)
public class UserDTO extends BaseDTO {
    @TableId
    private Long id;
    private String username;
    private String phone;

    public UserDTO(BaseEntity entity) {
        super(entity);
    }

    public static <T extends BaseEntity> List<UserDTO> convertEntityList(Collection<T> list) {
        if(list == null){
            return Collections.emptyList();
        }
        return list.stream().map(UserDTO::new).collect(Collectors.toList());
    }

}
